{extend name="common/application" /}
{block name="title"}<title>搜索中心-店铺搜索</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/reset.css">
<link rel="stylesheet" type="text/css" href="_CSS_/common.css">
<link rel="stylesheet" type="text/css" href="_CSS_/slide.css">
<link rel="stylesheet" type="text/css" href="_CSS_/search_work.css">
<link rel="stylesheet" type="text/css" href="_CSS_/scom.css"/>
<!--[if lt IE 9]>
<script src="http://www.ijquery.cn/js/html5shiv.js"></script>
<![endif]-->
{/block}



{block name="content"}
<!-- 主体内容 -->
<div class="main">
    <div class="mainBody normalBox clearfix" style="padding-top: 0px;">
        <div class="courses sectionArea normalBox" style="margin-top: 0px;">
            <!--搜索类别-->
            <div class="courseMenu">
                {include file="/common/course" /}
                <input type="hidden" id="value">
                <div class="serviceHeader">
                    <div class="serviceNavi fl">
                        <a class="sortType active" value="0" href="javascript:;">综合</a>
                        <a class="sortType" value="1" href="javascript:;">最新</a>
                        <a class="sortType" value="2" href="javascript:;">最热</a>
                    </div>
                    <div class="total fr">
                        <p class="mr20">共<span class="num" id="count"></span>个店铺</p>
                        <a class="prev" href="javascript:;">
                            <span class="icons icon-prev hide"></span>
                            <span class="icons icon-grey-prev"></span>
                        </a>
                        <p><span class="currentPage">1</span>/<span class="allPage"></span></p>
                        <a class="next" href="javascript:;">
                            <span class="icons icon-next"></span>
                            <span class="icons icon-grey-next hide"></span>
                        </a>
                    </div>
                </div>


                <!--相关店铺-->
                <div class="con-part government-part">
                    <div class="conBody">

                    </div>
                </div>
                <!--分页-->
                <div id="page"></div>
            </div>
        </div>
    </div>
</div>

{/block}
{block name="js"}
<!-- 脚本引入 -->
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/jquery.SuperSlide.2.1.2.js"></script>
<script>
    $('#sel_2').addClass('selected');
    $("a.selectType").eq(0).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_work')}?" + keyword;
    });
    $("a.selectType").eq(1).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_trade')}?" + keyword;
    });
    $("a.selectType").eq(2).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_store')}?" + keyword;
    });
    $("a.selectType").eq(3).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_courses')}?" + keyword;
    });
    $("a.selectType").eq(4).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_persons')}?" + keyword;
    });
    $("a.selectType").eq(5).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_teachers')}?" + keyword;
    });
    $("a.selectType").eq(6).on('click', function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
        window.location.href = "{:url('index/search/search_government')}?" + keyword;
    });

    $(function () {
        var keyword = decodeURI(window.location.href.split("?")[1]);
		$("#keyword").val(keyword);
        if (keyword == 'undefined') {
            keyword = null;
        }
        postfile(1, keyword);
    });


    $('.prev').on('click', function () {
        var value = $("#value").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var prev_num = parseInt($('.currentPage').html()) - 1;
        if (prev_num != 0) {
            postfile(prev_num, keyword, value);
        }
    });
    $('.next').on('click', function () {
        var value = $("#value").val();
        var keyword = decodeURI(window.location.href.split("?")[1]);
        var next_num = parseInt($('.currentPage').html()) + 1;
        var max_num = parseInt($('.allPage').html());
        if (next_num <= max_num) {
            postfile(next_num, keyword, value);
        }
    });

    $(".sortType").on('click', function () {
        $('.sortType').removeClass('active');
        $(this).addClass('active');
        var value = $(this).attr('value');
        $("#value").val(value);
        var keyword = decodeURI(window.location.href.split("?")[1]);
        postfile(1, keyword, value);
    });


    function postfile(page, keyword, value) {
        $.ajax({
            type: 'get',
            url: "{:url('api/keyword/search_store')}",
            data: {'page': page, 'keyword': keyword, 'value': value},
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    $('.num').html(msg.data.count);
                    $('.currentPage').html(page);
                    var pages = Math.ceil(msg.data.count / 10);
                    $('.allPage').html(pages);
                    $("#count").html(msg.data.count);
                    var re = /^[0-9]+$/;
                    var info = "";//店铺
                    //店铺
                    if (msg.data.info.length != 0) {
                        for (var j = 0; j < msg.data.info.length; j++) {
                            if (re.test((j + 1) / 2)) {
                                info += '<div class="storeitem mr0" all="' + msg.data.info[j].id + '">';
                            } else {
                                info += '<div class="storeitem" all="' + msg.data.info[j].id + '">';
                            }
                            info += '<div class="store-logo"><img src="/Images/Information/' + msg.data.info[j].image + '"></div>' +
                                '<div class="store-info"><div class="store-name"><p>' + msg.data.info[j].name + '</p></div>' +
                                '<div class="store-owner"><p>卖家：' + msg.data.info[j].username + '</p></div><div class="store-att">' +
                                '<p><span class="icons sp1">' + msg.data.info[j].shop_name + '</span><span class="icons icon-sp2"></span>' +
                                '<span class="icons icon-sp3"></span></p></div><div class="store-in"><p>' +
                                '<span>销量' + msg.data.info[j].shop_volume + '</span>' +
                                '<span>共' + msg.data.info[j].count + '件商品</span></p></div>' +
                                '<div class="store-scope"><p>主营：' + msg.data.info[j].scope + '</p></div>' +
                                '<div class="store-btn"><a href="/index.php/index/trade/center?' + msg.data.info[j].id + '">进店逛逛</a>' +
                                '<a class="contactStore" href="javascript:;">联系卖家</a></div></div></div>';
                        }
                        $(".conBody").html(info);
                        if (msg.data.info.length == 0) {
                            $('#page').html('');
                        } else {
                            $('#page').html(msg.data.render);
                            $("#pagination").delegate("a", "click", function () {
                                var value = $("#value").val();
                                var num = $(this).attr("num");
								
								
                                if (num) {
                                    postfile(num, keyword, value);
                                }
                            });
							$("#GO").on('click',function(){
								var king = $("#go").val();
								if(king > pages){
									layer.alert("最多输入"+pages+"页");
									return;
								}
								postfile(king, c_id, category, value);
							});
                        }
                        /*联系卖家*/
                        $('.contactStore').on('click', function () {
                            var id = $(this).parents('div.storeitem').attr('all');
                            var userinfo = $.cookie('userinfo');
                            if (userinfo) {
                                var user_login = $.base64.decode(userinfo).split(",");
                                var from_uid = user_login[0];
                                layer.open({
                                    type: 2,
                                    title: '联系卖家',
                                    fix: false,
                                    maxmin: true,
                                    shadeClose: true,
                                    scrollbar: false,
                                    area: ['560px', '490px'],
                                    content: 'contact.html?id=' + id,
                                    btn: ['发送', '取消'],
                                    yes: function (index, layero) {
                                        //do something

                                        var body = layer.getChildFrame('body', index);
                                        // var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                        //得到iframe页的body内容
                                        var content = body.find('#news_title').val();
                                        var to_uid = body.find('#uid').val();

                                        layer.close(index);//如果设定了yes回调，需进行手工关闭
                                        if (content != '' || title != '') {
                                            $.ajax({
                                                type: "get",
                                                url: "{:url('api/trading/trading_chat')}",
                                                data: {
                                                    'to_uid': to_uid,
                                                    'content': content,
                                                    'from_uid': from_uid
                                                },
                                                dataType: 'jsonp',
												beforeSend: function () {
												var index = layer.load(1, {
													shade: [0.1, '#333333'] //0.1透明度的白色背景
												});
												},
                                                success: function (msg) {
													layer.closeAll();
                                                    if (msg.code == 200) {
                                                        layer.msg('发送成功！', {icon: 1}, function () {
                                                        });
                                                    }
                                                    if (msg.code == 1000) {
                                                        layer.msg('发送失败！', {icon: 5});
                                                    }
                                                }
                                            });
                                        } else {
                                            layer.msg('不能为空！', {icon: 5});
                                        }
                                    }
                                });
                            } else {
                                layer.msg('你还没有登录！', {icon: 51});
                            }
                        });
                    } else {
                        var personnel = '<div class="nodatas normalBox">' +
                            '<img src="/static/web/images/nodata.png"/>' +
                            '<p>抱歉，找不到相关数据</p></div>';

                        $(".conBody").html(personnel);
                    }
                }
            }
        })
    }
</script>
{/block}